package com.org.buildcycle2;

import static org.anddev.andengine.extension.physics.box2d.util.constants.PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;

import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.extension.physics.box2d.util.Vector2Pool;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.sensor.accelerometer.AccelerometerData;
import org.anddev.andengine.sensor.accelerometer.IAccelerometerListener;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.Debug;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.hardware.SensorManager;
import android.view.MotionEvent;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
//I implemented code from AndEngine examples: http://code.google.com/p/andengineexamples
//Respective authors of AndEngine examples:
/**
 * (c) 2010 Nicolas Gramlich
 * (c) 2011 Zynga
 *
 * @author Nicolas Gramlich
 * @since 18:47:08 - 19.03.2010
 */
public class FallingBox extends BaseGameActivity implements IAccelerometerListener, IOnSceneTouchListener, IOnMenuItemClickListener {
	private Camera camera;
	
	private BitmapTextureAtlas coin_t; private TextureRegion coin_tr; private Sprite coin;
	private BitmapTextureAtlas coin_t1; private TextureRegion coin_tr1; private Sprite coin1;
	private BitmapTextureAtlas coin_t2; private TextureRegion coin_tr2; private Sprite coin2;
	private BitmapTextureAtlas coin_t3; private TextureRegion coin_tr3; private Sprite coin3;
	private BitmapTextureAtlas coin_t4; private TextureRegion coin_tr4; private Sprite coin4;
	private BitmapTextureAtlas coin_t5; private TextureRegion coin_tr5; private Sprite coin5;

	private BitmapTextureAtlas coin_t6; private TextureRegion coin_tr6; private Sprite coin6;
	private BitmapTextureAtlas coin_t7; private TextureRegion coin_tr7; private Sprite coin7;
	private BitmapTextureAtlas coin_t8; private TextureRegion coin_tr8; private Sprite coin8;
	private BitmapTextureAtlas coin_t9; private TextureRegion coin_tr9; private Sprite coin9;
	private BitmapTextureAtlas coin_t10; private TextureRegion coin_tr10; private Sprite coin10;
	private BitmapTextureAtlas coin_t11; private TextureRegion coin_tr11; private Sprite coin11;
	
	private BitmapTextureAtlas spike_t; private TextureRegion spike_tr; private Sprite spike;
	
	private AnimatedSprite dude;
	private TiledTextureRegion dude_tr;
	private BitmapTextureAtlas mFontTexture;
	private Font mFont;
      
	private int score = 0;

	//	private BitmapTextureAtlas dude_t;
	//private TextureRegion dude_tr;
	
	private BitmapTextureAtlas btnTexture;
	private TextureRegion btn_resetRegion;
	private Sprite resetBtn;
	
	//	private Sprite dude_sprite;
	private AnimatedSprite face;
	
	private static final int CAMERA_WIDTH = 720;
	private static final int CAMERA_HEIGHT = 480;

	private static final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

	// ===========================================================
	// Fields
	// ===========================================================

	private BitmapTextureAtlas mBitmapTextureAtlas;

	private TiledTextureRegion mBoxFaceTextureRegion;
	private TiledTextureRegion mCircleFaceTextureRegion;
	private TiledTextureRegion mTriangleFaceTextureRegion;
	private TiledTextureRegion mHexagonFaceTextureRegion;

	private Scene mScene;

	private PhysicsWorld mPhysicsWorld;
	private int mFaceCount = 0;

	// ===========================================================
	// Constructors
	// ===========================================================

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	@Override
	public Engine onLoadEngine() {
		//Toast.makeText(this, "Touch the screen to add a box.", Toast.LENGTH_LONG).show();
		camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
		engineOptions.getTouchOptions().setRunOnUpdateThread(true);
		engineOptions.getRenderOptions().disableExtensionVertexBufferObjects();
		return new Engine(engineOptions);
	}

	@Override
	//This function loads the coins, spikes, and any other obsticles that the player
	// must over come into the actual game.  There are multiple lines of code that look
	// the same but we are infact implementing the same coin or spike just in different places.
	public void onLoadResources() {
		this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);
		 
        this.mFont = new Font(this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.WHITE);

        this.getEngine().getTextureManager().loadTexture(this.mFontTexture);
        this.getEngine().getFontManager().loadFont(this.mFont);
        
        this.spike_t = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.spike_tr = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.spike_t, this, "gfx/spikes.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.spike_t);
        
		this.coin_t = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t);
		
		this.coin_t1 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t1, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t1);
		
		this.coin_t2 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t2, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t2);
		
		this.coin_t3 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr3 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t3, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t3);
		
		this.coin_t4 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr4 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t4, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t4);
		
		this.coin_t5 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr5 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t5, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t5);
		
		this.coin_t6 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr6 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t6, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t6);
		
		this.coin_t7 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr7 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t7, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t7);
		
		this.coin_t8 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr8 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t8, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t8);
		
		this.coin_t9 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr9 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t9, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t9);
		
		this.coin_t10 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr10 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t10, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t10);
		
		this.coin_t11 = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.coin_tr11 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.coin_t11, this, "gfx/coin.png", 0, 0);
		this.mEngine.getTextureManager().loadTexture(this.coin_t5);
		

		btnTexture = new BitmapTextureAtlas(64,32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		btn_resetRegion= BitmapTextureAtlasTextureRegionFactory.createFromAsset(btnTexture, this, "gfx/reset.png", 0,0);
		
		
		getEngine().getTextureManager().loadTexture(btnTexture);
		
		/* Textures. */
		this.mBitmapTextureAtlas = new BitmapTextureAtlas(64, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

		/* TextureRegions. */
		this.dude_tr = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "test_guy.png", 0, 0, 2, 1);
		this.mBoxFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "crate.png", 0, 0, 2, 1); // 64x32
		this.mCircleFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "face_circle_tiled.png", 0, 32, 2, 1); // 64x32
		this.mTriangleFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "face_triangle_tiled.png", 0, 64, 2, 1); // 64x32
		this.mHexagonFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "face_hexagon_tiled.png", 0, 96, 2, 1); // 64x32
		this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
	}

	@Override
	//This function will load the coins in the correct location that we have specified.
	public Scene onLoadScene() {
		this.mEngine.registerUpdateHandler(new FPSLogger());

		this.mScene = new Scene();
		this.mScene.setBackground(new ColorBackground(0, 0, 0));
		this.mScene.setOnSceneTouchListener(this);

		this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

		final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2);
		final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
		final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
		final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);

		final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
		PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

		this.mScene.attachChild(ground);
		this.mScene.attachChild(roof);
		this.mScene.attachChild(left);
		this.mScene.attachChild(right);

		this.mScene.registerUpdateHandler(this.mPhysicsWorld);
		
		spike = new Sprite(315, 445, this.spike_tr); mScene.attachChild(spike);
		
		coin = new Sprite(200, 400, this.coin_tr); mScene.attachChild(coin);
		coin1 = new Sprite(200, 415, this.coin_tr1); mScene.attachChild(coin1);
		coin2 = new Sprite(200, 430, this.coin_tr2); mScene.attachChild(coin2);
		coin3 = new Sprite(215, 400, this.coin_tr3); mScene.attachChild(coin3);
		coin4 = new Sprite(215, 415, this.coin_tr4); mScene.attachChild(coin4);
		coin5 = new Sprite(215, 430, this.coin_tr5); mScene.attachChild(coin5);
	
		coin6 = new Sprite(400, 400, this.coin_tr6); mScene.attachChild(coin6);
		coin7 = new Sprite(400, 415, this.coin_tr7); mScene.attachChild(coin7);
		coin8 = new Sprite(400, 430, this.coin_tr8); mScene.attachChild(coin8);
		coin9 = new Sprite(415, 400, this.coin_tr9); mScene.attachChild(coin9);
		coin10 = new Sprite(415, 415, this.coin_tr10); mScene.attachChild(coin10);
		coin11 = new Sprite(415, 430, this.coin_tr11); mScene.attachChild(coin11);
		
		final ChangeableText textCenter = new ChangeableText(100, 60, this.mFont, ""+score);
        mScene.attachChild(textCenter);
		
		dude  = new AnimatedSprite(200, 100, this.dude_tr);
		Body body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, dude, BodyType.DynamicBody, FIXTURE_DEF);
		dude.animate(200);

		
	this.mScene.attachChild(dude);
	this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(dude, body, true, true));
		//dude_sprite = new Sprite(CAMERA_WIDTH/2,457, this.dude_tr);
		//mScene.attachChild(dude_sprite);
		
		

		resetBtn= new Sprite(CAMERA_WIDTH- this.btn_resetRegion.getWidth()-100, 50, this.btn_resetRegion){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
	   			 if(pSceneTouchEvent.getAction()==MotionEvent.ACTION_UP){
	   				 this.setVisible(false);
	   				restart_game();
	   			 }
	   			 return true;
       	}};
       	resetBtn.setScale(2);
       	mScene.attachChild(resetBtn);
       	mScene.registerTouchArea(resetBtn);
		
       	mScene.registerUpdateHandler(new IUpdateHandler(){
			@Override
			//This function updates what happens when the sprite runs into the coin, spike
			//or obstacle.  
			public void onUpdate(float pSecondsElapsed) {
				if (dude.collidesWith(spike))
				{
				mScene.detachChild(dude);
				}
				
				if (dude.collidesWith(coin))
				{
					score = score +10;
				
				mScene.detachChild(coin);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin1))
				{
					score = score +10;
				mScene.detachChild(coin1);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin2))
				{
					score = score +10;
				mScene.detachChild(coin2);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin3))
				{
					score = score +10;
				mScene.detachChild(coin3);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin4))
				{
					score = score +10;
				mScene.detachChild(coin4);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin5))
				{
					score = score +10;
				mScene.detachChild(coin5);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin6))
				{
					score = score +10;
				
				mScene.detachChild(coin6);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin7))
				{
					score = score +10;
				mScene.detachChild(coin7);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin8))
				{
					score = score +10;
				mScene.detachChild(coin8);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin9))
				{
					score = score +10;
				mScene.detachChild(coin9);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin10))
				{
					score = score +10;
				mScene.detachChild(coin10);
			  textCenter.setText("" + (score));
				}
				
				if (dude.collidesWith(coin11))
				{
					score = score +10;
				mScene.detachChild(coin11);
			  textCenter.setText("" + (score));
				}
			}

			@Override
			public void reset() {
				// TODO Auto-generated method stub
				
			}
       		
       	});
       	
		return this.mScene;
	}


	@Override
	public void onLoadComplete() {

	}

	@Override
	public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
		if(this.mPhysicsWorld != null) {
			if(pSceneTouchEvent.isActionDown()) {
				//this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
				return true;
			}
		}
		return false;
	}

	@Override
	//This function is used for the gravity control
	public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
		final Vector2 gravity = Vector2Pool.obtain(pAccelerometerData.getX(), pAccelerometerData.getY());
		this.mPhysicsWorld.setGravity(gravity);
		Vector2Pool.recycle(gravity);
	}

	@Override
	public void onResumeGame() {
		super.onResumeGame();

		this.enableAccelerometerSensor(this);
	}

	@Override
	public void onPauseGame() {
		super.onPauseGame();

		this.disableAccelerometerSensor();
	}

	// ===========================================================
	// Methods
	// ===========================================================

	private void addFace(final float pX, final float pY) {
		Debug.d("Faces: " + this.mFaceCount);

		final Body body;

		if(this.mFaceCount == 0) {
			face = new AnimatedSprite(pX, pY, this.mBoxFaceTextureRegion);
			body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);
			face.animate(200);

		this.mScene.attachChild(face);
		this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, body, true, true));
		this.mFaceCount++;
		}
	
		
	}


	
	//The following methods are unused shape methods. For now, I am only using box
	//Possibly later in development, we'll use different polygons as obstacles
	private static Body createTriangleBody(final PhysicsWorld pPhysicsWorld, final Shape pShape, final BodyType pBodyType, final FixtureDef pFixtureDef) {
		/* Remember that the vertices are relative to the center-coordinates of the Shape. */
		final float halfWidth = pShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
		final float halfHeight = pShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;

		final float top = -halfHeight;
		final float bottom = halfHeight;
		final float left = -halfHeight;
		final float centerX = 0;
		final float right = halfWidth;

		final Vector2[] vertices = {
				new Vector2(centerX, top),
				new Vector2(right, bottom),
				new Vector2(left, bottom)
		};

		return PhysicsFactory.createPolygonBody(pPhysicsWorld, pShape, vertices, pBodyType, pFixtureDef);
	}

	/**
	 * Creates a {@link Body} based on a {@link PolygonShape} in the form of a hexagon:
	 * <pre>
	 *  /\
	 * /  \
	 * |  |
	 * |  |
	 * \  /
	 *  \/
	 * </pre>
	 */
	private static Body createHexagonBody(final PhysicsWorld pPhysicsWorld, final Shape pShape, final BodyType pBodyType, final FixtureDef pFixtureDef) {
		/* Remember that the vertices are relative to the center-coordinates of the Shape. */
		final float halfWidth = pShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
		final float halfHeight = pShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;

		/* The top and bottom vertex of the hexagon are on the bottom and top of hexagon-sprite. */
		final float top = -halfHeight;
		final float bottom = halfHeight;

		final float centerX = 0;

		/* The left and right vertices of the heaxgon are not on the edge of the hexagon-sprite, so we need to inset them a little. */
		final float left = -halfWidth + 2.5f / PIXEL_TO_METER_RATIO_DEFAULT;
		final float right = halfWidth - 2.5f / PIXEL_TO_METER_RATIO_DEFAULT;
		final float higher = top + 8.25f / PIXEL_TO_METER_RATIO_DEFAULT;
		final float lower = bottom - 8.25f / PIXEL_TO_METER_RATIO_DEFAULT;

		final Vector2[] vertices = {
				new Vector2(centerX, top),
				new Vector2(right, higher),
				new Vector2(right, lower),
				new Vector2(centerX, bottom),
				new Vector2(left, lower),
				new Vector2(left, higher)
		};

		return PhysicsFactory.createPolygonBody(pPhysicsWorld, pShape, vertices, pBodyType, pFixtureDef);
	}

	@Override
	public boolean onMenuItemClicked(MenuScene arg0, IMenuItem arg1,
			float arg2, float arg3) { 
		return true;
	}
	
	public void restart_game()
	{
		Intent intent = new android.content.Intent(); 
        intent.setClass(this, this.getClass());
        this.startActivity(intent); 
        return;
	}

}
